<?php
// +----------------------------------------------------------------------
// | OneThink [ WE CAN DO IT JUST THINK IT ]
// +----------------------------------------------------------------------
// | Copyright (c) 2015 http://www.dingxiaoyu.com All rights reserved.
// +----------------------------------------------------------------------
// | Author: 
// +----------------------------------------------------------------------

namespace Common\Model;
use Think\Model;

/**
 * 用户模型
 * @author 
 */

class CommentModel extends Model {

    protected $_validate = array(
		array('message','require','评论内容不能为空！'), //默认情况下用正则进行验证
        array('message', '8,500', '评论内容过短或过长', self::EXISTS_VALIDATE, 'length'),
    );

    protected $_auto = array (
            array('status','1'),  // 新增的时候把status字段设置为1    
            array('time','time',1,'function'),
            array('ip','getIp',1,'callback'),
    );

    public function lists($status = 1, $order = 'uid DESC', $field = true){
        $map = array('status' => $status);
        return $this->field($field)->where($map)->order($order)->select();
    }

    public function addComment($aid ,$message){
    	$data = array(
    		"uid" => is_login(),
			"aid" => $aid,
    		"message" => $message,
    		);
    	if($this->create($data)){
    		$uid = $this->add(); 
    		if($uid > 0){
				
    		}
    	}else{
    		$uid = -1;
    	}
    	return $uid;
    }

	public function getIp(){
		return ip2long(get_client_ip());
	}
}
